package br.com.inner.custom;

import java.io.UnsupportedEncodingException;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public class MailDestinatario {
	
	private InternetAddress destinatarios[];

	
	public MailDestinatario(String email) throws AddressException  {
		this.setDestinatario(email);
	}
	
	public MailDestinatario(String[] emails) throws AddressException{
		this.setDestinatarios(emails);
	}

	public MailDestinatario(String email, String nome) throws UnsupportedEncodingException {
		this.setDestinatario(email,nome);
	}
	
	public MailDestinatario(String[] emails, String[] nomes) throws UnsupportedEncodingException{
		this.setDestinatarios(emails,nomes);
	}

	public void setDestinatario(String email) throws AddressException{
		this.destinatarios = new InternetAddress[1];
		this.destinatarios[0] = new InternetAddress(email);
	}
	
	public void setDestinatario(String email, String nome) throws UnsupportedEncodingException{
		this.destinatarios = new InternetAddress[1];
		this.destinatarios[0] = new InternetAddress(email,nome);
	}
	
	public void setDestinatario(InternetAddress destinatario){
		this.destinatarios = new InternetAddress[1];
		this.destinatarios[0] = destinatario;
	}
	
	public void setDestinatarios(String[] email) throws AddressException{
		
		if ( email != null && email.length > 0){
			this.destinatarios = new InternetAddress[email.length];
			for (int i = 0; i < email.length; i++) {
				this.destinatarios[i] = new InternetAddress(email[i]);
			}
		}
	}
	
	public void setDestinatarios(String[] email, String[] nome) throws UnsupportedEncodingException {
		
		if ( email != null && email.length > 0 && nome != null && nome.length > 0 && email.length == nome.length) {
			this.destinatarios = new InternetAddress[email.length];
			for (int i = 0; i < email.length; i++) {
				this.destinatarios[i] = new InternetAddress(email[i],nome[i]);
			}
		}
	}
	
	public void setDestinatarios(InternetAddress[] destinatarios){
		this.destinatarios = destinatarios;
	}
	
	public InternetAddress[] getDestinatarios(){
		return this.destinatarios;
	}
	
	public InternetAddress getDestinatario(){
		
		if ( this.destinatarios != null && this.destinatarios.length > 0 ) {
			return this.destinatarios[0];
		} else {
			return null;
		}
	}
	
	
}

